{% extends 'base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}
{% block content %}
        <br>
        {% for message in get_flashed_messages(with_categories=True) %}
    <div class="alert alert-{{ message[0] }}" role="alert">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {{ message[1] }}
    </div>
    {% endfor %}
    <br>
    <div class="page-header">
        <h1>分类
            <small class="text-muted">{{ pagination.total }}</small>
            <span class="float-right"><a href="{{ url_for('.new_category') }}" class="btn btn-primary">发布新的分类</a></span>
        </h1>
    </div>
    {% if categories %}
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>编号.</th>
                    <th>标题</th>
                    <th>动作</th>
                </tr>
            </thead>
        {% for category in categories %}
        <tr>
            <td>{{ loop.index+((pagination.page - 1)*20) }}</td>
            <td><a href="{{ url_for('blog.show_category',category_id=category.id) }}">{{ category.name }}</a></td>

            <td>
                <form action="{{ url_for('.delete_category',category_id=category.id) }}" method="post" class="inline">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure to delete this category?');">Delete</button>
                </form>
            </td>
        </tr>
        {% endfor %}
        </table>
        <div class="page-footer">{{ render_pagination(pagination) }}</div>
        {% else %}
        <div class="tip"><h5>没有文章。</h5></div>
    {% endif %}

{% endblock %}